<?php

class Banners extends Controller {
	
	function index()
	{
	   $template = $this->loadView('banners/banners_lista');
       $banners = "Controle de Banners - Listagem";
       $template->smarty->assign('banners',$banners);
       $listagem = $this->loadModel('banners_model');
       $template->smarty->assign('lista',$listagem->listaBanners());
       $template->render();
	}
    
    function form()
	{        
	    $funcoes = $this->loadHelper('funcoes_gerais');
	    $bannersModel = $this->loadModel('banners_model');
        $template = $this->loadView('banners/banners_cadastro');       
        $template->smarty->assign('posicoes',$bannersModel->listaPosicoes());
        $template->smarty->assign('marcas', $bannersModel->listaMarcas());
        $template->smarty->assign('status', $funcoes->listaStatus('A'));
        $template->render();
        
	}
        
    function posicoes()
	{
	    $funcoes = $this->loadHelper('funcoes_gerais');
		$template = $this->loadView('banners/banners_posicoes');
        $listagem = $this->loadModel('banners_model');
        $template->smarty->assign('lista',$listagem->listaPosicoes());
        
        $template->render();
	}
    
    function excluir($banCod)
    {
       $clientes = $this->loadModel('banners_model');
       $clientes->excluirBanner($banCod);
    }
    
    function excluirPosicoes($codPos)
    {
       $posicoes = $this->loadModel('banners_model');
       $posicoes->excluirPosicao($codPos);
    }
    
    function cadastroPosicoes()
    {
        $template = $this->loadView('banners/banners_posicoes_cadastro');
        $banners_pos = $this->loadModel('banners_model');
        $template->render();
    }
    
    function cadastroPosicoesdb()
    {
       $template = $this->loadView('banners/banners_posicoes_cadastro');
       $template->smarty->assign('form', $_POST);
       if(isset($_POST['desPos'])){
            $banners = $this->loadModel('banners_model');
            $banners->cadastroPosicoes();       
       }
       $template->render();
    }
    
    function editaPosicoes($codPos = '')
    {
        $template = $this->loadView('banners/banners_posicoes_edita');
        $banners_pos = $this->loadModel('banners_model');
        if($codPos != ''){
            $banners_pos = $banners_pos->editarBannerPosicao($codPos); 
            $template->smarty->assign('codPos',$banners_pos['codPos']);   
            $template->smarty->assign('desPos',$banners_pos['desPos']);
        }
        $template->render();
    }
    
    function editaPosicoesdb()
    {
       $template = $this->loadView('banners/banners_posicoes_edita');
       $template->smarty->assign('form', $_POST);
       if(isset($_POST['desPos'])){
            $banners = $this->loadModel('banners_model');
            $banners->editaPosicoes($_POST['codPos'],$_POST['desPos']);       
       }
       $template->render();
    }
    
    function cadastrodb()
    {
       $template = $this->loadView('banners/banners_lista');
       $template->smarty->assign('form', $_POST);
       if(isset($_POST['banTit'])){
            $emailModel = $this->loadModel('banners_model');
            $emailModel->insertBanner();       
       }
       $template->render();
    }
    
    function edita($banCod = '')
	{        
	    $funcoes = $this->loadHelper('funcoes_gerais');
	    $bannersModel = $this->loadModel('banners_model');
        $template = $this->loadView('banners/banners_editar');       
        $template->smarty->assign('posicoes',$bannersModel->listaPosicoes());
        $template->smarty->assign('marcas', $bannersModel->listaMarcas());
        
        if($banCod != ''){
            $banner = $bannersModel->editarBanner($banCod);
            $template->smarty->assign('banCod',$banner['banCod']); 
            $template->smarty->assign('banTip',$banner['banTip']);   
            $template->smarty->assign('marCod',$banner['marCod']);
            $template->smarty->assign('banLoc',$banner['banLoc']);   
            $template->smarty->assign('banTar',$banner['banTar']);
            $template->smarty->assign('banTit',$banner['banTit']);   
            $template->smarty->assign('banUrl',$banner['banUrl']);
            $template->smarty->assign('banMail',$banner['banMail']);   
            $template->smarty->assign('status', $funcoes->listaStatus($banner['banSta']));
        }
        $template->render();
        
	}
    
    function editadb($banCod = '')
    {
       $template = $this->loadView('banners/banners_lista');
       $template->smarty->assign('form', $_POST);
       if(isset($_POST['banTit'])){
            $banners = $this->loadModel('banners_model');
            $banners->editaBannerdb($_POST);       
       }
       $template->render();
    }
    
    function editaImagem($banCod = '')
	{        
        $template = $this->loadView('banners/banners_editar_imagem');
        $bannersModel = $this->loadModel('banners_model');
        $banner = $bannersModel->editarBanner($banCod);   
        $template->smarty->assign('banCod',$banner['banCod']); 
        $template->smarty->assign('banArq',$banner['banArq']);     
        $template->render();
        
	}
    
    function editaImagemdb($banCod = '')
    {
       $template = $this->loadView('banners/banners_lista');
       $template->smarty->assign('form', $_POST);
       if(isset($_POST['banCod'])){
            $banners = $this->loadModel('banners_model');
            $banner = $banners->editarBanner($_POST['banCod']); 
            $banners->editaBannerImagem($_POST,$_FILES,$banner['banArq']);       
       }
       $template->render();
    }
    
    function trocaStatus($banCod,$banSta)
    {
       $template = $this->loadView('banners/banners_lista');
       $banners = $this->loadModel('banners_model');
       $status = $banners->trocaStatus($banCod,$banSta);
       $template->render();
    }
}

?>
